﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lt.Workflow;
using RayDen.Library.Core.Components;
using RayDen.Library.Entity.Interface;

namespace Lt.Services
{
    public class WorkflowItemsFactory : Singleton<WorkflowItemsFactory>
    {
        private readonly Dictionary<Type, Func<IParameterBag, IWorkflowItem>> factory;

        public WorkflowItemsFactory()
        {
            factory = new Dictionary<Type, Func<IParameterBag, IWorkflowItem>>();
            factory.Add(typeof(CustomActionWorkflowItem), (p) => new CustomActionWorkflowItem(p.Get<Action<object[]>>("Action")));


        }

        public TWorkflowItem Create<TWorkflowItem>(IParameterBag parameters)
            where TWorkflowItem:IWorkflowItem
        {
            return (TWorkflowItem) factory[typeof (TWorkflowItem)](parameters);
        }

        public IWorkflowItem CreateCustomAction(Action<object[]> act)
        {
            return new CustomActionWorkflowItem(act);
        }

    }
}
